package com.wdf.controller;

import com.github.pagehelper.PageInfo;
import com.wdf.pojo.Emp;
import com.wdf.pojo.PageResult;
import com.wdf.pojo.Result;
import com.wdf.pojo.query.EmpQuery;
import com.wdf.service.EmpService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result pageEmp(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize){
        log.info("查询员工信息, page={}, pageSize={}", page, pageSize);
        PageResult pageResult = empService.pageList(page,pageSize);
        return Result.success(pageResult);
    }

    @PostMapping("/list")
    public Result pageListEmp(@RequestBody @Valid EmpQuery empQuery){
        log.info("条件查询员工信息：" + empQuery);
        return Result.success(empService.list(empQuery));
    }

    @PostMapping("/add")
    public Result addEmp(@RequestBody @Valid Emp emp){
        log.info("请求员工参数："+emp);
        empService.addEmp(emp);
        return Result.success();
    }
}
